import cn.stylefeng.guns.sys.core.util.ReadFile;
import cn.stylefeng.guns.sys.core.util.UUIDUtils;
import cn.stylefeng.guns.sys.modular.system.ApiEntity.ExpandInfo;
import cn.stylefeng.guns.sys.modular.system.ApiEntity.HykData;
import cn.stylefeng.guns.sys.modular.system.entity.BtyHyk;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/***
 *  if (ToolUtil.isNotEmpty(hykData.getExpandInfo())) {
 *                     if (ToolUtil.isNotEmpty(hykData.getExpandInfo().getConsumeCash())) {
 *                         hyk.setXfbj(hykData.getExpandInfo().getConsumeCash() == null ? BigDecimal.ZERO : hykData.getExpandInfo().getConsumeCash());
 *                     }
 *                 }
 *                 if (hykData.getTradeTypeId().equals("2") | hykData.getTradeTypeId().equals("29") && ToolUtil.isNotEmpty(hykData.getExpandInfo())) {
 *                     hyk.setCzje(hykData.getExpandInfo().getRechargeAmount() == null ? BigDecimal.ZERO : hykData.getExpandInfo().getRechargeAmount());
 *                 }
 *                 if (hykData.getTradeTypeId().equals("30") && ToolUtil.isNotEmpty(hykData.getExpandInfo())) {
 *                     hyk.setXfbj(hykData.getExpandInfo().getConsumeCash() == null ? BigDecimal.ZERO : hykData.getExpandInfo().getConsumeCash().multiply(new BigDecimal(-1)));
 *                 }
 *                 hyk.setJylx(hykData.getTradeTypeId());
 *                 hyk.setCzlxmc(hykData.getTsTypeName());
 *                 hyk.setJysj(hykData.getCreateTime());
 */
public class TestRead {
    public static void main(String[] args){
        BufferedReader reader = null;
        //BufferedReader reader = new BufferedReader(new FileReader("D:\\hyksj\\[1000002886-20210719110243]交易查询.zip\\[1000002886-20210719110243]交易查询.txt"));
        try {
            String fileName="D:\\hyksj\\[1000002886-20210719110243]交易查询.zip\\[1000002886-20210719110243]交易查询.txt";
            File file = new File(fileName);

            reader = new BufferedReader(new FileReader(file));
            String tempStr;
            while ((tempStr = reader.readLine()) != null) {
                HykData hykData=new HykData();
                JSONObject jsonObject = JSONObject.parseObject(tempStr);
                hykData.setXfShopName(jsonObject.getString("xfShopName"));
                hykData.setTradeTypeId(jsonObject.getString("tradeTypeId"));
                hykData.setTsTypeName(jsonObject.getString("tsTypeName"));
                ExpandInfo expandInfo=jsonObject.getObject("expandInfo",ExpandInfo.class);
                //BigDecimal consumeCash=  expandInfo.getConsumeCash();
//                System.out.println("consumeCash:"+consumeCash);
//                System.out.println(jsonObject.getString("xfShopName"));
//                System.out.println(jsonObject.getString("tradeTypeId"));
//                System.out.println(jsonObject.getString("tsTypeName"));

                BtyHyk hyk = new BtyHyk();
                hyk.setId(UUIDUtils.getId());
                hyk.setDm(hykData.getXfShopName());
                if (ToolUtil.isNotEmpty(expandInfo)) {
                    if (ToolUtil.isNotEmpty(expandInfo.getConsumeCash())) {
                        hyk.setXfbj(expandInfo.getConsumeCash() == null ? BigDecimal.ZERO : expandInfo.getConsumeCash());
                    }
                }
                if (hykData.getTradeTypeId().equals("2") | hykData.getTradeTypeId().equals("29") && ToolUtil.isNotEmpty(expandInfo)) {
                    hyk.setCzje(expandInfo.getRechargeAmount() == null ? BigDecimal.ZERO : expandInfo.getRechargeAmount());
                }
                if (hykData.getTradeTypeId().equals("30") && ToolUtil.isNotEmpty(expandInfo)) {
                    hyk.setXfbj(expandInfo.getConsumeCash() == null ? BigDecimal.ZERO : expandInfo.getConsumeCash().multiply(new BigDecimal(-1)));
                }
                hyk.setJylx(hykData.getTradeTypeId());
                hyk.setCzlxmc(hykData.getTsTypeName());
                hyk.setJysj(hykData.getCreateTime());
                //hyk.setYyr(yesterDayDate);
               // hykService.save(hyk);

            }

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }

//        String fileName="D:\\hyksj\\[1000002886-20210719110243]交易查询.zip\\[1000002886-20210719110243]交易查询.txt";
//        String content= ReadFile.readFileContent(fileName);
//        System.out.println("content:"+content);
//        JsonParser jp2 = new JsonParser();
//        JsonArray array = jp2.parse(content).getAsJsonArray();
//        System.out.println(array.get(0));
        //List<HykData> list4 = JSONArray.parseArray(array, HykData.class);
        //System.out.println(list4.size());



    }
}
